<?php

/*========================================================================*\
|| ###################################################################### ||
|| # uCash Version 4                                                    # ||
|| # ----------------------------------------------------------------   # ||
|| # A Geeky Designs Production!                                        # ||
|| # Written by: Matthew Gordon                                         # ||
|| # This may not be redistributated without consent from Geeky Designs # ||
|| # Copyright 2009 Geeky Designs                                       # ||
|| ###################################################################### ||
\*========================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'ucash_admin');
define('UCASH_VERSION', '4.0.0 Beta');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_ucash.php');

// ############################# LOG ACTION ###############################
log_admin_action();

print_cp_header("uCash ".UCASH_VERSION." Admin");

$ucashfield = ucash_data_location($vbulletin->options['ucash_pointsfield']);

if (!isset($_REQUEST['do']) || empty($_REQUEST['do'])) {
	$_REQUEST['do'] = "dolist";
}

// ##################### POINTS FOR EXISTING POSTS ###########################
if ($_REQUEST['do'] == "ppp") {
	print_form_header('ucash_admin', 'doppp');
	print_table_header("<font size='2'><b>Give $vbphrase[ucash_points] For Existing Posts</b></font>");
	print_description_row("This is a quick method of giving users points for their current amount of posts. Everyone's point values will be increased by their post count multiplied by the setting below.");
	print_input_row("Points Per Post", 'ppp', $vbulletin->options['ucash_perreply']);

	print_submit_row("Give $vbphrase[ucash_points]");
}

if ($_REQUEST['do'] == "doppp") {
	$vbulletin->input->clean_gpc('p', 'ppp', TYPE_NUM);
	
	if ($vbulletin->GPC['ppp'] != 0) {
		if ($ucashfield['table'] == TABLE_PREFIX . "user") {
			// user table, very easy query.
			$db->query_write("UPDATE $ucashfield[table] SET $ucashfield[field] = posts * " . $vbulletin->GPC['ppp'] . " + $ucashfield[field]");
		} else {
			// not user table, still easy query.
			$db->query_write("UPDATE $ucashfield[table] ucash, ".TABLE_PREFIX."user user SET ucash.$ucashfield[field] = user.posts * " . $vbulletin->GPC['ppp'] . " + ucash.$ucashfield[field] WHERE ucash.userid=user.userid");
		}
		print "<b><font size=\"2\">Points successfully given!</font></b>";
	} else {
		print "<b><font size=\"2\">You must enter a non-zero amount of points.</font></b>";
	}
	print "<br /><br />";
	$_REQUEST['do'] = "dolist";
}

// ##################### LIST ALL AVAILABLE ACTIONS ########################
if ($_REQUEST['do'] == "dolist") {
	print_form_header('ucash_admin', 'nowhere');
	print_table_header("Select An Action");
	print_description_row("<a href=\"options.php?dogroup=ucash\">$vbphrase[ucash_options]</a>");
	print_description_row("<a href=\"ucash_admin.php?do=ppp\">Give Points For Existing Posts</a>");
	print_table_footer();
}

print_cp_footer();

?>